package com.yueban.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import com.loopj.android.image.SmartImageView;
import com.yueban.R;
import com.yueban.constant.HttpConstant;

import java.util.List;

/**
 * Created by guan on 17-8-12.
 */

public class HomePictureGridAdapter extends BaseAdapter {
    private LayoutInflater layoutInflater;
    private List<String> imageNames;

    public HomePictureGridAdapter(Context context, List<String> imageNames) {
        this.layoutInflater = LayoutInflater.from(context);
        this.imageNames = imageNames;
    }

    @Override
    public int getCount() {
        if (imageNames == null)
            return 0;
        return imageNames.size();
    }

    @Override
    public Object getItem(int i) {
        return imageNames.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        MyViewHolder myViewHolder;
        if (view == null) {
            view = layoutInflater.inflate(R.layout.item_home_content_gridview, null);
            myViewHolder = new MyViewHolder(view);
            view.setTag(myViewHolder);
        } else {
            myViewHolder = (MyViewHolder) view.getTag();
        }
        myViewHolder.imageView.setImageUrl(HttpConstant.SERVER_URL + HttpConstant.GET_ACTIVITY_PICTURES +
                "?imageName=" + imageNames.get(i));
        return view;
    }

    private class MyViewHolder {
        private SmartImageView imageView;

        private MyViewHolder(View view) {
            imageView = (SmartImageView) view.findViewById(R.id.activity_picture);
        }
    }
}
